<template>
  <a-tree-select v-model="curVal" :treeData="treeData" :replaceFields="replaceFields" @select="onSelect" v-bind="$attrs"></a-tree-select>
</template>

<script>
export default {
  components: {},
  props: {
    value: String,
    table: String
  },
  data() {
    return {
      curVal: undefined,
      treeData: [],
      replaceFields: { children: 'Children', title: 'Name', key: 'Id', value: 'Id' }
    }
  },
  watch: {
    value(newVal) {
      this.curVal = newVal
    }
  },
  mounted() {
    this.curVal = this.value
    this.$http.get(`/api/${this.table}/GetTree`).then(result => {
      this.treeData = result.Data
    })
  },
  methods: {
    onSelect(value, node, extra) {
      this.$emit('input', value)
      this.$emit('select', value, node.dataRef, extra)
    }
  }
}
</script>

<style>
</style>
